<?php
require "common.php";


//$id = $_GET['id'];
//$article = one("select * from `article` where id='$id'");
//$comments = all("select *from `comment` where `pid`='$id'");
//
//
//if ($_POST){
//    $nickname = $_POST['author'];
//    $content = $_POST['content'];
//    $time=time();
//    mysql_query("insert into `comment`(`nickname`,`content`,`time`,`pid`)values('$nickname','$content','$time','$id')");
//    echo "<script>alert('评论成功');location=location</script>";
//}
//
//
//$smarty->assign('article',$article);
//$smarty->assign('comments',$comments);
//$smarty->display('show.html');

class ShowController extends CommonController{

    function show(){
            $id = $_GET['id'];
            $article = $this->one("select * from article where id = '$id'");
            $comments = $this->all("select * from comment where pid = '$id'");
        if ($_POST){
            $nickname = $_POST['author'];
            $content = $_POST['content'];
            $time = time();
            $res = $this->add("insert into `comment`(`nickname`,`content`,`time`,`pid`)values('$nickname','$content','$time','$id')");
            if($res)
                $this->redirect("评论成功");
            $this->redirect("评论失败");
        }
        $this->assign("comments",$comments);
        $this->assign("article",$article);//引号里的值是传给模版变量的名称,第二个是获取的值的名称
        $this->display("show.html");
    }

}
$show = new ShowController();
$show->show();